package com.harlaus.controller;

import com.harlaus.entity.CommonResult;
import com.harlaus.entity.Payment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/consumer/payment")
public class OrderController {
//    private static final String url = "http://localhost:8001/payment/";
    private static final String url = "http://CLOUD-PAYMENT-SERVICE/payment"; //使用需要调用的远程服务在Eureka中的名称

    @Autowired
    RestTemplate restTemplate;

    @GetMapping("/create")
    public CommonResult create(@RequestBody Payment payment){
        return restTemplate.postForObject(url + "/create",payment,CommonResult.class);
    }

    @GetMapping("/query/{id}")
    public CommonResult query(@PathVariable Long id){
        return restTemplate.getForObject(url + "/query/" + id,CommonResult.class);
    }
}
